﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
#if NET40
using Autofac.Extras.DynamicProxy2;
#else
using Autofac.Extras.DynamicProxy;
#endif
using Log.Common;
using Mvvm.Common;
using Mvvm.Common.Aop;

namespace WPFCommon.Test.ViewModel
{
    public class MainViewModel : ViewModelBase,IViewModel, IModelLoaded, IModelDialog, IModelClosing, IModelDialogResult,
        IModelCloseCompleted
    {
        private ILog _log;

        public MainViewModel(ILog log)
        {
            _log = log;
        }


        [CalcRunTime()]
        public virtual void Loaded()
        {
            _log.Info("窗体加载中");
            DialogModel.ShowDialog("窗体加载");
        }

        public DialogModel DialogModel { get; } = new DialogModel();

        public bool Closing()
        {
            var isTrue = DialogResultModel.ShowDialog("您确定要关闭当前窗口吗?");
            return isTrue == true;
        }

        public DialogResultModel DialogResultModel { get; } = new DialogResultModel();
        public void CloseCompleted()
        {
            _log.Info("窗口关闭完成");
        }
#if NETCOREAPP3_1
        [CalcRunTime]
        public virtual async Task AopReturnTest()
        {
            await Task.Delay(2000);
            Debug.WriteLine("dd");
        }
#endif

    }
}
